package top.tangyh.lamp.care.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.tangyh.lamp.care.mapper.BDevBedRelationMapper;
import top.tangyh.lamp.care.service.BDevBedRelationService;
import top.tangyh.basic.base.service.impl.SuperServiceImpl;
import top.tangyh.lamp.care.manager.BDevBedRelationManager;
import top.tangyh.lamp.care.entity.BDevBedRelation;
import top.tangyh.lamp.care.vo.save.BDevBedRelationSaveVO;
import top.tangyh.lamp.care.vo.update.BDevBedRelationUpdateVO;
import top.tangyh.lamp.care.vo.result.BDevBedRelationResultVO;
import top.tangyh.lamp.care.vo.query.BDevBedRelationPageQuery;

/**
 * <p>
 * 业务实现类
 * 床号设备绑定关系表
 * </p>
 *
 * @author zqb
 * @date 2024-08-23 15:19:59
 * @create [2024-08-23 15:19:59] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class BDevBedRelationServiceImpl extends SuperServiceImpl<BDevBedRelationManager, Integer, BDevBedRelation> implements BDevBedRelationService {

    private final BDevBedRelationMapper bDevBedRelationMapper;


    @Override
    public int count(BDevBedRelation devBedRelation) {
        QueryWrapper<BDevBedRelation> queryWrapper = new QueryWrapper();
//        queryWrapper.eq("dev_code",devBedRelation.getDevCode());
        queryWrapper.eq("dev_type", devBedRelation.getDevType());
        queryWrapper.eq("bed_number", devBedRelation.getBedNumber());

        int count = Math.toIntExact(bDevBedRelationMapper.selectCount(queryWrapper));
        return count;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteByDevCode(String devCode, Integer devType) {
        QueryWrapper<BDevBedRelation> wrapper = new QueryWrapper<>();
        wrapper.eq("dev_code", devCode);
        wrapper.eq("dev_type", devType);

        int result = bDevBedRelationMapper.delete(wrapper);
        return result;
    }


}


